package com.yueya.media.mongo;

import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * Created by Robby on 2018/3/26.
 */
@Component
public interface ICollectionDao {
    /**
     * Get Data BY ID
     *
     * @param Id
     * @return
     * @throws Exception
     */
    Map<String, Object> queryByID(String collectionName, String Id) throws Exception;

    /**
     * Get Data BY DOC
     *
     * @param collectionName
     * @param doc
     * @return
     */
    List<Map<String, Object>> queryByDoc(String collectionName, Map<String, Object> doc);

    /**
     * Count By Doc
     *
     * @param collectionName
     * @param doc
     * @return
     */
    long countByDoc(String collectionName, Map<String, Object> doc);

    /**
     * Insert Data
     *
     * @param obj
     * @return
     */
    boolean insert(String collectionName, DBObject obj);

    /**
     * Insert Batch
     *
     * @param collectionName
     * @param documents
     * @return
     */
    boolean insertBatch(String collectionName, List<DBObject> documents);

    /**
     * Delete Many Data.if doc is empty will delete all Data
     *
     * @param doc
     * @return
     */
    boolean delete(String collectionName, BasicDBObject doc);

    /**
     * Delete One Data
     *
     * @param collectionName
     * @param Id
     * @return
     */
    boolean deleteByID(String collectionName, String Id);

    /**
     * Update All Data
     *
     * @param oldDoc
     * @param newDoc
     * @return
     */
    boolean update(String collectionName, BasicDBObject oldDoc, BasicDBObject newDoc);
}
